package com.dxj1992.config;


import com.dxj1992.intercepter.AdminInterceptor;
import com.dxj1992.intercepter.RbacInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class GlobalConfig implements WebMvcConfigurer {
    /**
     * 管理员拦截器
     * @return
     */
    @Bean
    public HandlerInterceptor getAdminInterceptor() {
        return new AdminInterceptor();
    }

    /**
     * 权限拦截器
     * @return
     */
    @Bean
    public HandlerInterceptor getRbacInterceptor() {
        return new RbacInterceptor();
    }

    /**
     * 添加全局拦截器
     *
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        //管理员拦截
        registry.addInterceptor(getAdminInterceptor()).addPathPatterns("/admin/**")
                .excludePathPatterns("/admin/doLogin","/admin/logout");

        //权限拦截
        registry.addInterceptor(getRbacInterceptor()).addPathPatterns("/admin/**")
                .excludePathPatterns("/admin/doLogin");
    }

}
